﻿var SplitManualType;//暂存手工拆分方式："0":按数量，"1":按单价
var OldPrint = null;
Ext.define('HIT.controller.DealPrint', {
    extend: 'Ext.app.Controller',
    models: ['Search'],
    stores: ['DealPrint'],
    views: ['DealPrintGrid','DealOrderWin','DealOrderPanel',
            'AIPrintWayWindow','DealPrintSimplePanel',
            'DealPrintComplexSearchWin','DealPrintComplexSearchPanel'],
//发票打印菜单controller
    onButtonClick: function(button, e, options) {
    	var p;
    	var tabpanelId = 'tab-deal-print';
        var tab = Ext.getCmp(tabpanelId);
        if (tab == undefined) {
            return;
        }
        
        if(button.id == 'deal-print-print'){//发票打印功能的打印按钮
        	var aaa = Ext.getCmp('win-aiprintwaywindow');
        	if (aaa != undefined) {
        		return;
        	}
        	var selModel5 = tab.getSelectionModel();
                if (selModel5.hasSelection()){
                    var model5= selModel5.getSelection();
                    for (var k = 0; k < model5.length; k++) {
                    var doc_status_code = model5[k].get('doc_status_code');//获得票据状态
					if(doc_status_code == 2 || doc_status_code == 4){
						Share.ShowMessage("E0028", "'已审核'");
						return;
					}
                    }
                }
        	var type = Ext.getCmp("print-invtype").getValue();//获得发票类型
        	var invConfig = Share.invoiceInitConfig(type);//获取对应票据设置 ,参数type为对应类型如：“N_VAT”  
        	var interfaceWay = invConfig.PRINT_TYPE;//获得接口方式：“AI”,"TXT","EXCEL"

        	if(interfaceWay=='AI'){  
            	p = Ext.create('widget.aiprintwaywindow');//显示AI打印窗口
            	p.show();

        	}else if(interfaceWay=='TXT'){//导出TXT格式  就是以前的导出航天功能
            	var selModel = tab.getSelectionModel();
                if (selModel.hasSelection()){
                    var models = selModel.getSelection();
                    var type = Ext.getCmp("print-invtype").getValue();//获得发票类型
                    var ids = [];
                    var invType = Ext.getCmp('print-invtype').getValue();//票据类型
                    for(var j=0;j<models.length;j++){
                    	var amount = models[j].get('total_amount');
                    	var line = models[j].get('total_line');
                    	var invConfig = Share.invoiceInitConfig(invType);//对应类型设置
                    	if(amount > invConfig.MAX_AMOUNT){
                    		Share.showMsg("E","E0060","E0061"," "+models[j].get('document_no')+" ");
                    		return;
                    	}
                    	if(line > invConfig.MAX_LINE){
                    		Share.showMsg("E","E0060","E0062"," "+models[j].get('document_no')+" ");
                    		return;
                    	}
                    	var doc_status_code = models[j].get('doc_status_code');//获得票据状态
                    	if(doc_status_code != 3 && doc_status_code != 4){
                    		Share.ShowMessage("E0028", "'已审核'和'已导出'");
                    		return;
                    	}
                    	ids.push(models[j].get('id_head_id'));         	
                    }
                    var Ids = ids.join(",");

                    //先发送ajax请求将要操作的数据的状态置为'已导出',如果操作成功则进行导出TXT操作
                	Share.AjaxRequest({
                 		 url: ctx + "/setExportPrintExcel",
                          params: {Ids:Ids},
                          showMsg: false,
                          callback: function (json) {
                       	   if(json.resultcode == "0"){//状态设置成功,进行导出TXT操作
                           	   tab.getStore().load();
                           	   window.location.href = ctx + '/dealPrintDownload/'+type+'/download';
                       	   }else{  
                       		   Share.ShowMessage("I0004", "操作");
                       		   return;
                       	   }

                          }
                     });
                }else{
                	Share.ShowMessage("I0011", "需要操作的行");
    				return;
                }
        	}else if(interfaceWay=='EXCEL'){//导出excel格式
            	var selModel = tab.getSelectionModel();
                if (selModel.hasSelection()){
                    var models = selModel.getSelection();
                    var ids = [];
                    var invType = Ext.getCmp('print-invtype').getValue();//票据类型
                    for(var j=0;j<models.length;j++){
                    	var amount = models[j].get('total_amount');
                    	var line = models[j].get('total_line');
                    	var invConfig = Share.invoiceInitConfig(invType);//对应类型设置
                    	if(amount > invConfig.MAX_AMOUNT){
                    		Share.showMsg("E","E0060","E0061"," "+models[j].get('document_no')+" ");
                    		return;
                    	}
                    	if(line > invConfig.MAX_LINE){
                    		Share.showMsg("E","E0060","E0062"," "+models[j].get('document_no')+" ");
                    		return;
                    	}
                    	var doc_status_code = models[j].get('doc_status_code');
                    	if(doc_status_code != 3 && doc_status_code != 4){
                    		Share.ShowMessage("E0028", "'已审核'和'已导出'");
                    		return;
                    	}
                    	ids.push(models[j].get('id_head_id'));         	
                    }
                    var Ids = ids.join(",");
                    
                  //先发送ajax请求将要操作的数据的状态置为'已导出',如果操作成功则进行导出excel操作
                	Share.AjaxRequest({
                  		 url: ctx + "/setExportPrintExcel",
                           params: {Ids:Ids},
                           showMsg: false,
                           callback: function (json) {
                        	   if(json.resultcode == "0"){//状态设置成功,进行导出excel操作
                            	   tab.getStore().load();
                            	   window.location.href = ctx + '/dealPrintExportExcel/'+invType+'/download';
                        	   }else{
                        		   Share.ShowMessage("I0004", "操作");
                        		   return;
                        	   }
                           }
                      });
                }else{
                	Share.ShowMessage("I0011", "需要操作的行");
    				return;
                }
//                tab.getStore().load();
        	}else{
        		Share.ShowMessage("E0029");
        		return;
        	}
        }else if(button.id == "deal-order"){//按钮“排序”，弹出排序编辑窗口
        	var win = Ext.create('widget.dealorderwin');
        	Share.AjaxRequest({
       		 url: ctx + "/getPrintOrder",
                params: {},
                showMsg: false,
                callback: function (json) {
                	var orderPanel = Ext.getCmp('deal-order-panel');
                	  for(var i = 0 ;i<json.length;i++){
                		  var name = json[i].field_name;
                		  var dir = json[i].is_asc==0 ? "desc":"asc";
                		  var newPanel = Ext.create('widget.dealorderpanel');
                		  var items = newPanel.getLayout().getLayoutItems();
                		  items[0].setValue(name);
                		  items[1].setValue(dir);
                		  orderPanel.add(newPanel);
                	  };
                	  win.show();
                }
           }); 
        }else if(button.id == 'deal-cancel-audit'){//按钮“取消审核”
        	var selModel = tab.getSelectionModel();
            if (selModel.hasSelection()) {
                var models = selModel.getSelection();
                var ids = [];
                for(var i=0;i<models.length;i++){     
                	if(models[i].get('doc_status_code') != 3){
                		Share.ShowMessage("E0009","已审核");
                		return;
                	}  
                  ids.push(models[i].get('id_head_id'));//满足条件的放入数组id中
                }
                Ext.Ajax.request({
        			// 从controller返回的response中读取数据
        			url : 'cancelAudit',
        			params : {ids : ids.join(",")},
        			async : false,
        			success : function(response) {
        				json = Ext.JSON.decode(response.responseText);
        				if (json.resultcode == '0') {
  							tab.getStore().reload(); 	
  							var searchgrid = Ext.getCmp('tab-deal-search');
  					        if (searchgrid != undefined) {
  					        	searchgrid.getStore().load();
  					        }
  					        Share.ShowMessage("I0006", "");
  						} else {
  							Share.ShowMessage("I0007", "");
  						}
        			}
        		});
            }else{
            	Share.ShowMessage("I0011","需要操作的行");
				return;
            }
        }else if (button.id == 'deal-import-aer'){//按钮'打印回写'就是之前的“导入航天” 
        	var type = Ext.getCmp("print-invtype").getValue();//获得发票类型
        	var invConfig = Share.invoiceInitConfig(type);//获取对应票据设置 ,参数type为对应类型如：“N_VAT”  
        	var back_type = invConfig.ACK_TYPE;//获得接口方式："TXT","EXCEL"
        	//获得回写方式
        	if(back_type == 'TXT'){
        		var win = new Ext.window.Window({
                    width : 650,
                    title : Share.T('导入txt数据'),
                    height : 400,
                    layout : 'fit',
                    modal : true,
                    items : [ {
                        xtype : 'fileuploadPanel',
                        alldone: false,
                        border : false,
                        uploadLimit: "1",
                        fileTypes : '*.txt',//可上传文件类型
                        postParams : {}, //http请求附带的参数
                        uploadUrl : ctx + '/io/ImportAerMapping/upload;jsessionid=' + $.cookie('JSESSIONID'),
                        flashUrl : ctx + '/resources/swfupload/swfupload.swf',
                        uploadSuccess : function(file, server_data) { // json string 
                            jsonObj = Ext.decode(server_data); // json object
                            if(jsonObj.resultcode == '0' ){
                          	  win.close();
                          	  Share.ShowMessage("I0006", "航天数据导入");
                          	  Ext.getCmp('tab-deal-print').getStore().load();
                            }else if(jsonObj.resultcode == '99'){
                              Share.ShowMessage("E0011");
                          	  win.close();
                          	  return;
                            } else {
                            	win.close();
                                Share.ShowMessage("I0006", jsonObj.resultcode);
                            	var store = Ext.data.StoreManager.lookup("fileItems");
                            	store.removeAll();
                            	return;
                            }
                        }
                    } ]
                }).show();
        	}else if(back_type == 'EXCEL'){
        		var win = new Ext.window.Window({
                    width : 650,
                    title : Share.T('导入excel数据'),
                    height : 400,
                    layout : 'fit',
                    modal : true,
                    items : [ {
                        xtype : 'fileuploadPanel',
                        alldone: false,
                        border : false,
                        uploadLimit: "1",
                        fileTypes : '*.xls;*.xlsx',//可上传文件类型
                        postParams : {}, //http请求附带的参数
                        uploadUrl : ctx + '/io/ImportExcelAerMapping/upload;jsessionid=' + $.cookie('JSESSIONID'),
                        flashUrl : ctx + '/resources/swfupload/swfupload.swf',
                        uploadSuccess : function(file, server_data) { // json string 
                            jsonObj = Ext.decode(server_data); // json object
                            if(jsonObj.resultcode == '0'){
                          	  win.close();
                          	  Share.ShowMessage("I0006", "航天数据导入");
                          	  Ext.getCmp('tab-deal-print').getStore().load();
                            }else if(jsonObj.resultcode == '99'){
                              Share.ShowMessage("E0011");
                          	  win.close();
                          	  return;
                            } else {
                            	Share.ShowMessage("I0007","数据连接");
                              return;
                            }
                        }
                    } ]
                }).show();
        	}
    }else if(button.id == "deal-order-save"){//保存排序
    	var orderPanel = Ext.getCmp('deal-order-panel');
    	var paramPanels = orderPanel.getLayout().getLayoutItems();
    	var str = [];
    	var fieldNames = [];
    	for(var i=0;i<paramPanels.length;i++){
    		var basicForm = paramPanels[i].getForm();
    		if (!basicForm.isValid()) {//不可为空
                return;
            }
    		var panelItems = paramPanels[i].getLayout().getLayoutItems();
    		var fieldName = panelItems[0].getValue();
    		var orderDir = panelItems[1].getValue();
    		fieldNames.push(fieldName);
    		str.push(fieldName+' '+orderDir);//拼写orderby语句
    	}   
    	var hash = {};          	  
        for(var i in fieldNames) {//判断字段名有无重复     
            if(hash[fieldNames[i]]){
            	Share.ShowMessage("I0052");
                return ;      
            }
            hash[fieldNames[i]] = true;           
        }  
    	Share.AjaxRequest({//排序信息写入或更新
    		 url: ctx + "/savePrintOrder",
             params: {
            	 strs: str
             },
             showMsg: false,
             callback: function (json) {
                if(json.resultcode == "0"){
                	var gridStore = tab.getStore();//grid重新排序
                	gridStore.on('beforeload', function(store) {
                		Ext.apply(store.proxy.extraParams , {order_param : str.join(",")});        			
                	});
                	gridStore.load();
                	orderPanel.up('panel').close();//关闭“排序”弹出框
                }else{
                	Share.ShowMessage("I0007","");
                }
             }
    	});        	
//    }else if(button.id == 'invtype-query'){//grid查询按钮（发票类型）   
//    	  var type = Ext.getCmp('print-invtype').getValue();
//    	  var store = tab.getStore();
//    	   store.currentPage = 1;
//    	   store.on('beforeload', function(store) {
//   			 Ext.apply(store.proxy.extraParams , {type : type});        			
//      		});
//    	   store.load();
    }else if(button.id == 'deal-print-preview'){//按钮“预览打印”
    	var clientIp = Ext.getCmp("printClientIp").getValue();
    	if (clientIp == null || clientIp == undefined || clientIp == '') {
    		Ext.Msg.alert(Share.T('错误'), Share.T("请先输入打印电脑的IP地址。"));
    		return;
    	}
    	Ext.state.Manager.set('PrinterClientIP', clientIp);
    	
    	var selModel = tab.getSelectionModel();
        if (selModel.hasSelection()){
            var models = selModel.getSelection();
            var ids = [];
            var printMode=0;
            var invType = Ext.getCmp('print-invtype').getValue();//票据类型
            for(var j=0;j<models.length;j++){
            	var amount = models[j].get('total_amount');
            	var line = models[j].get('total_line');
            	var invConfig = Share.invoiceInitConfig(invType);//对应类型设置
            	if(amount > invConfig.MAX_AMOUNT){
            		Share.showMsg("E","E0060","E0061"," "+models[j].get('document_no')+" ");
            		return;
            	}
            	if(line > invConfig.MAX_LINE){
            		Share.showMsg("E","E0060","E0062"," "+models[j].get('document_no')+" ");
            		return;
            	}
            	var doc_status_code = models[j].get('doc_status_code');//得到票据状态
            	if(doc_status_code != 3 && doc_status_code != 2 && doc_status_code != 4){
            		Share.ShowMessage("E0028", "'已审核','打印中'，和'已导出'");
            		return;
            	}
            	ids.push(models[j].get('document_no'));         	
            }
            var Ids = ids.join(",");
            var win = button.up('panel').up('window');
            Share.AjaxRequest({
       		 url: ctx + "/dealPrint",
                params: {
               	 Ids       :  Ids
               	,printMode :  printMode
               	,clientIp : clientIp
                },
                showMsg: false,
                callback: function (json) {
                    	if(json.resultcode == "0"){
                        	  //成功
                    		  Share.ShowMessage("I0028");
                       		  win.close();                   		
                       		  tab.getStore().load();
                        	  
                          }else if(json.resultcode == "9"){
                        	  //失败
                        	  var port = json.resultPort;
                        	  win.close();
                        	  Share.ShowMessage("E0013", port);
                          }else if(json.resultcode == "1"){
                        	  //失败
                        	  Share.ShowMessage("E0001", "数据连接");
                       		  win.close();
                          }else if(json.resultcode == "2"){
                        	  //失败
                        	  Share.ShowMessage("E0001", "文件");
                       		  win.close();
                          }
                }
       	   });
 //           window.location.href = ctx + '/dealPrint/'+Ids+'/'+printMode+'/download';
        }else{
        	Share.ShowMessage("I0011", "需要操作的行");
			return;
        }
    }else if(button.id == 'deal-print-auto'){//按钮“全自动打印”
    	var clientIp = Ext.getCmp("printClientIp").getValue();
    	if (clientIp == null || clientIp == undefined || clientIp == '') {
    		Ext.Msg.alert(Share.T('错误'), Share.T("请先输入打印电脑的IP地址。"));
    		return;
    	}
    	Ext.state.Manager.set('PrinterClientIP', clientIp);
    	
    	var selModel = tab.getSelectionModel();
        if (selModel.hasSelection()){
            var models = selModel.getSelection();
            var ids = [];
            var printMode=1;
            var invType = Ext.getCmp('print-invtype').getValue();//票据类型
            for(var j=0;j<models.length;j++){
            	var amount = models[j].get('total_amount');
            	var line = models[j].get('total_line');
            	var invConfig = Share.invoiceInitConfig(invType);//对应类型设置
            	if(amount > invConfig.MAX_AMOUNT){
            		Share.showMsg("E","E0060","E0061"," "+models[j].get('document_no')+" ");
            		return;
            	}
            	if(line > invConfig.MAX_LINE){
            		Share.showMsg("E","E0060","E0062"," "+models[j].get('document_no')+" ");
            		return;
            	}
            	var doc_status_code = models[j].get('doc_status_code');//得到票据状态
            	if(doc_status_code != 3 && doc_status_code != 2 && doc_status_code != 4){
            		Share.ShowMessage("E0028", "'已审核','打印中'，和'已导出'");
            		return;
            	}
            	ids.push(models[j].get('document_no'));         	
            }
            var Ids = ids.join(",");
            var win = button.up('panel').up('window');
            Share.AjaxRequest({
          		 url: ctx + "/dealPrint",
                   params: {
                  	 Ids       :  Ids
                  	,printMode :  printMode
                   	,clientIp : clientIp
                   },
                   showMsg: false,
                   callback: function (json) {
	                   	if(json.resultcode == "0"){
	                    	  //成功
	                   		  Share.ShowMessage("I0028");
	                   		  win.close();                   		
	                   		  tab.getStore().load();
	                    	  
	                      }else if(json.resultcode == "9"){
	                    	  //失败
                        	  var port = json.resultPort;
                        	  win.close();
                        	  Share.ShowMessage("E0013", port);
	                      }else if(json.resultcode == "1"){
                        	  //失败
	                    	  Share.ShowMessage("E0001", "数据连接");
                       		  win.close();
                          }else if(json.resultcode == "2"){
                        	  //失败
                        	  Share.ShowMessage("E0001", "文件");
                       		  win.close();
                          }
                   }
          	   });
        }else{
        	Share.ShowMessage("I0011", "需要操作的行");
			return;
        }
    }else if(button.id == 'deal-print-semiauto'){//按钮“半自动打印”
    	var clientIp = Ext.getCmp("printClientIp").getValue();
    	if (clientIp == null || clientIp == undefined || clientIp == '') {
    		Ext.Msg.alert(Share.T('错误'), Share.T("请先输入打印电脑的IP地址。"));
    		return;
    	}
    	Ext.state.Manager.set('PrinterClientIP', clientIp);

    	var selModel = tab.getSelectionModel();
        if (selModel.hasSelection()){
            var models = selModel.getSelection();
            var ids = [];
            var printMode=2;
            var invType = Ext.getCmp('print-invtype').getValue();//票据类型
            for(var j=0;j<models.length;j++){
            	var amount = models[j].get('total_amount');
            	var line = models[j].get('total_line');
            	var invConfig = Share.invoiceInitConfig(invType);//对应类型设置
            	if(amount > invConfig.MAX_AMOUNT){
            		Share.showMsg("E","E0060","E0061"," "+models[j].get('document_no')+" ");
            		return;
            	}
            	if(line > invConfig.MAX_LINE){
            		Share.showMsg("E","E0060","E0062"," "+models[j].get('document_no')+" ");
            		return;
            	}
            	var doc_status_code = models[j].get('doc_status_code');//得到票据状态
            	if(doc_status_code != 3 && doc_status_code != 2 && doc_status_code != 4){
            		Share.ShowMessage("E0028", "'已审核','打印中'，和'已导出'");
            		return;
            	}
            	ids.push(models[j].get('document_no'));         	
            }
        	
        	Ext.Msg.prompt(Share.T("提示"), Share.T("请输入打印张数"), function(btn, text){//显示要输入的张数对话框
        	    if (btn == 'ok'){       	    	
                    var nums;//要打印的张数
        	        nums = text;                   
                    var win = button.up('panel').up('window');
                    var Ids = ids.join(",");
                    Share.AjaxRequest({
                  		 url: ctx + "/dealPrint",
                           params: {
                          	 Ids       :  Ids,
                          	 printMode :  printMode,
                          	 nums      :nums,
                          	 clientIp : clientIp
                           },
                           showMsg: false,
                           callback: function (json) {
        	                   	if(json.resultcode == "0"){
        	                    	  //成功
        	                   		  Share.ShowMessage("I0028");
        	                   		  win.close();                   		
        	                   		  tab.getStore().load();
        	                    	  
        	                      }else if(json.resultcode == "9"){
        	                    	  //失败
                                	  var port = json.resultPort;
                                	  win.close();
                                	  Share.ShowMessage("E0013", port);
        	                      }else if(json.resultcode == "1"){
                                	  //失败
        	                    	  Share.ShowMessage("E0001", "数据连接");
                               		  win.close();
                                  }else if(json.resultcode == "2"){
                                	  //失败
                                	  Share.ShowMessage("E0001", "文件");
                               		  win.close();
                                  }
                           }
                  	   });
        	    }
        	});

        }else{
        	Share.ShowMessage("I0011", "需要操作的行");
			return;
        }
    }else if(button.id == 'deal-print-simple'){//调用一般查询窗口
    	var s_win = Ext.create('widget.dealprintsimplepanel');
    	Share.showWindow(s_win,true);      
    } else if (button.id == 'deal-print-complex') {//"高级查询"
//  	  console.log("OldSearch: "+OldSearch);
	  	if(OldPrint == null){
	  		var p_win = Ext.create('widget.printcomplexsearchwin');
	  		OldPrint = p_win;
	  		p_win.onEsc = function(){
	  			return;
//	  			this.hide();
	  		};
	  		Share.showWindow(p_win,true);
	  	}else{
	  		try{
	  			OldPrint.show();
	  		}catch(e){
	  			var p_win = Ext.create('widget.printcomplexsearchwin');
    	  		Share.showWindow(p_win,true);
	  		}
	  	}
    }else if(button.id == 'simplePrint'){//一般查询按钮
     	var tabPanel = Ext.getCmp('tab-deal-print');
  		var store = tabPanel.getStore();
    	var panel = Ext.getCmp('print-simple-panel');
    	var win = panel.up('window');
    	var id = panel.activeTab.id;
    	var state1 = Ext.getCmp('print-simple-state1').getValue();
  		state1 = Share.changeCombox(state1);
  		var state2 = Ext.getCmp('print-simple-state2').getValue();
  		state2 = Share.SearchCombox(state2);
  		var type = Ext.getCmp('print-invtype').getValue();
    	if(id == 'print-custom-tab'){//单据号查询
    		//单据号从
    		var startnum = Ext.ComponentMgr.get("deal-print-snum").getValue() == null ? "":Ext.ComponentMgr.get("deal-print-snum").getValue();
    		//单据号到
      		var endnum = Ext.ComponentMgr.get("deal-print-enum").getValue()== null ? "":Ext.ComponentMgr.get("deal-print-enum").getValue();
      		//单据号
      		var nums = Ext.ComponentMgr.get("deal-print-nums").getValue().toString()== null ? "":Ext.ComponentMgr.get("deal-print-nums").getValue().toString();
      		//日期从
      		var startday = Ext.ComponentMgr.get("num_sp_day").getValue()== null ? "":Ext.ComponentMgr.get("num_sp_day").getValue();
      		//日期到
      		var endday = Ext.ComponentMgr.get("num_ep_day").getValue()== null ? "":Ext.ComponentMgr.get("num_ep_day").getValue();    
      		//发票号码从
      		var doc_no = Ext.ComponentMgr.get("doc_p_no").getValue()== null ? "":Ext.ComponentMgr.get("doc_p_no").getValue();    
      		//发票号码到
      		var doc_no_2 = Ext.ComponentMgr.get("doc_p_no_2").getValue()== null ? "":Ext.ComponentMgr.get("doc_p_no_2").getValue();    
      		
      		store.currentPage = 1;
      		store.removeAll();
      	       store.on('beforeload', function(store) {
     			  Ext.apply(store.proxy.extraParams , {startnum:startnum
     				                                 ,endnum:endnum
     				                                 ,nums:nums
     				                                 ,startday:startday
     				                                 ,endday:endday
     				                                 ,doc_no:doc_no
     				                                 ,doc_no_2:doc_no_2
     				                                 ,state1 : state1
     				                                 ,state2 : state2
     				                                 ,type : type
     				                                 ,str:null
     				                                 });
            });
              store.load();
    	   }else if(id == 'print-payer-tab'){//付款单位查询
    		    var custname = Ext.ComponentMgr.get("deal-print-payer").getValue()== null ? "":Ext.ComponentMgr.get("deal-print-payer").getValue();
         		var startday = Ext.ComponentMgr.get("no_sp_day").getValue()== null ? "":Ext.ComponentMgr.get("no_sp_day").getValue();
         		var endday = Ext.ComponentMgr.get("no_ep_day").getValue()== null ? "":Ext.ComponentMgr.get("no_ep_day").getValue();     
          		store.currentPage = 1;
          		store.removeAll();
                store.on('beforeload', function(store) {
	         			Ext.apply(store.proxy.extraParams , {
	         				                                 startday:startday
	         				                                 ,endday:endday
	         				                                 ,custname:custname
	         				                                 ,state1:state1
	         				                                 ,state2:state2
	         				                                 ,type : type
	         				                                 ,str:null
	         				                                 });
                });
                store.load();
    	   }else if(id == 'print-goods-tab'){//商品名称查询
    		   var goodsname = Ext.getCmp('deal-print-goods').getRawValue();
        		var startday = Ext.ComponentMgr.get("goods_sp_day").getValue()== null ? "":Ext.ComponentMgr.get("goods_sp_day").getValue();
        		var endday = Ext.ComponentMgr.get("goods_ep_day").getValue()== null ? "":Ext.ComponentMgr.get("goods_ep_day").getValue();     
        		
         		store.currentPage = 1;
         		store.removeAll();
                store.on('beforeload', function(store) {
	         			Ext.apply(store.proxy.extraParams , {
	         				                                 startday:startday
	         				                                 ,endday:endday
	         				                                 ,goodsname:goodsname
	         				                                 ,state1:state1
	         				                                 ,state2:state2
	         				                                 ,type : type
	         				                                 ,str:null
	         				                                 });
               });
               store.load();
    	   }
    	  win.close();
    }
    else if (button.id == 'complex-print-save') {//执行高级查询  
    	var tabPanel = Ext.getCmp('tab-deal-print');
    	var PrintDetailArray = new Array();//存放查询数据的二维数组
 		var store = tabPanel.getStore();
 		//增加高级查询中三个条件
		var state1 = Ext.getCmp('print-complex-state1').getValue();
		state1 = Share.changeCombox(state1);
		var state2 = Ext.getCmp('print-complex-state2').getValue();
		state2 = Share.SearchCombox(state2);
		var type = Ext.getCmp('print-invtype').getValue();
 		var PrintPanel = Ext.getCmp('print-complex-panel');
 		OldPrint = button.up('window');
 		var paramPanels = PrintPanel.getLayout().getLayoutItems();
 		var str = [];
 		var disstr = [];
    	var fieldNames = [];
    	for(var i=0;i<paramPanels.length;i++){
    		PrintDetailArray[i] = new Array();  //存放查询数据的二维数组
    		var panelItems = paramPanels[i].getLayout().getLayoutItems();
    		if(panelItems[3].isHidden() == false){
    			if(panelItems[3].getValue() == '' || panelItems[3].getValue() == null){
    				Share.ShowMessage("E0030");
    				return;
    			}
    		}
    		for(var j = 0;j<panelItems.length;j++){
    			if(panelItems[j].isHidden() == true){break;}
    			if(panelItems[j].isHidden() == false && (panelItems[j].getValue() == '' || panelItems[j].getValue() == null)){
    				Share.ShowMessage("E0030");
    				return;
    			}
    		}
    		var fieldName = panelItems[0].getValue(); //combobox的valueField
    		var rawName = panelItems[0].getRawValue(); //combobox的displayField
    		var conName = panelItems[1].getRawValue();
    		PrintDetailArray[i][0] = rawName;  //Array_RawValue
    		PrintDetailArray[i][1] = conName;  //Array_condition
    		var orderDir = null;
    		var order2Dir = null;
    		fieldNames.push(fieldName);
    		if(panelItems[1].getValue() == 'between'){  //使用between
    			if(panelItems[0].getValue() == 'document_date' || panelItems[0].getValue() == 'create_date' || panelItems[0].getValue() == 'update_time' || panelItems[0].getValue() == 'INVOICE_DATE' || panelItems[0].getValue() == 'EXPRESS_DATE'){  //使用日期
    				temp = panelItems[3].getRawValue();   //2为text，3为date
    				PrintDetailArray[i][4] = 3;
    				orderDir = temp;
    				PrintDetailArray[i][2] = orderDir;
    				order2Dir = panelItems[6].getRawValue();  //5为text，6为date
    				PrintDetailArray[i][5] = 6;
    				PrintDetailArray[i][3] = order2Dir;
						if(panelItems[0].getValue() == 'update_time'){
							str.push("("+'convert(varchar,UPDATE_TIME ,23)'+conName+' '+"'"+orderDir+"'" + ' and ' + "'" +order2Dir+"'"+")"); 
							}
        				if(panelItems[0].getValue() == 'document_date'){
							str.push("("+'convert(varchar,DOCUMENT_DATE ,23)'+conName+' '+"'"+orderDir+"'" + ' and ' + "'" +order2Dir+"'"+")"); 
							}
        				if(panelItems[0].getValue() == 'INVOICE_DATE'){
							str.push("("+'convert(varchar,INVOICE_DATE ,23)'+conName+' '+"'"+orderDir+"'" + ' and ' + "'" +order2Dir+"'"+")"); 
							}
							if(panelItems[0].getValue() == 'EXPRESS_DATE'){
							str.push("("+'convert(varchar,EXPRESS_DATE ,23)'+conName+' '+"'"+orderDir+"'" + ' and ' + "'" +order2Dir+"'"+")"); 
							}    				
							disstr.push("("+rawName+' '+conName+' '+"'"+orderDir+"'" + ' and ' + "'" +order2Dir+"'"+")");
    			}else{//不使用日期
//    				SearchDetailArray[i][1] = 'text';
    				orderDir = panelItems[2].getValue();
    				PrintDetailArray[i][4] = 2;
    				order2Dir = panelItems[5].getValue();
    				PrintDetailArray[i][5] = 5;
    				str.push("("+fieldName+' '+conName+' '+"'"+orderDir+"'" + ' and ' + "'" +order2Dir+"'"+")");
    				disstr.push("("+rawName+' '+conName+' '+"'"+orderDir+"'" + ' and ' + "'" +order2Dir+"'"+")");
    			}
    		}else{ //不使用between
    			if(panelItems[0].getValue() == 'document_date' || panelItems[0].getValue() == 'create_date' || panelItems[0].getValue() == 'update_time' || panelItems[0].getValue() == 'INVOICE_DATE' || panelItems[0].getValue() == 'EXPRESS_DATE'){//使用日期
    				temp = panelItems[3].getRawValue();//2为text，3为date
    				PrintDetailArray[i][4] = 3;
    				PrintDetailArray[i][2] = temp;
    				if(panelItems[1].getValue() == 'like'){
    					temp = "%"+temp+"%";  //如果是like，则使用通配符
    				
    				orderDir = temp;
    				if(panelItems[0].getValue() == 'update_time'){
        								str.push('convert(varchar,UPDATE_TIME ,23)'+' '+'like'+' '+"'"+orderDir+"'");
        							}
        							if(panelItems[0].getValue() == 'document_date'){
        							str.push('convert(varchar,DOCUMENT_DATE ,23)'+' '+'like'+' '+"'"+orderDir+"'");
        							}
        							if(panelItems[0].getValue() == 'INVOICE_DATE'){
        								str.push('convert(varchar,INVOICE_DATE ,23)'+' '+'like'+' '+"'"+orderDir+"'");
        							}
        							if(panelItems[0].getValue() == 'EXPRESS_DATE'){
        							str.push('convert(varchar,EXPRESS_DATE ,23)'+' '+'like'+' '+"'"+orderDir+"'");
        							}	
    				}
    				if(panelItems[1].getValue() == 'in'){  //如果是in
    					orderDir = '';
    					orderTemp = panelItems[3].getRawValue();  //获取第一个textfield值  [2]为date，[3]为text 
    					PrintDetailArray[i][2] = orderTemp;
    					for(var l=0;l<orderTemp.split(",").length;l++){//如果是in，则为每一个in的条件增加''号
        					orderDir += "'"+orderTemp.split(",")[l]+"'";
        					if(l+1 != orderTemp.split(",").length){orderDir += ',';} 
        				}
									if(panelItems[0].getValue() == 'update_time'){
        					str.push('convert(varchar,UPDATE_TIME ,23)'+' '+conName+' '+"("+orderDir+")");   //将document_date变为convert(varchar,DOCUMENT_DATE ,23)
        							}
        							if(panelItems[0].getValue() == 'document_date'){
        					str.push('convert(varchar,DOCUMENT_DATE ,23)'+' '+conName+' '+"("+orderDir+")");   //将document_date变为convert(varchar,DOCUMENT_DATE ,23)
        							}
        							if(panelItems[0].getValue() == 'INVOICE_DATE'){
        					str.push('convert(varchar,INVOICE_DATE ,23)'+' '+conName+' '+"("+orderDir+")");   //将document_date变为convert(varchar,DOCUMENT_DATE ,23)
        							}
        							if(panelItems[0].getValue() == 'EXPRESS_DATE'){
        					str.push('convert(varchar,EXPRESS_DATE ,23)'+' '+conName+' '+"("+orderDir+")");   //将document_date变为convert(varchar,DOCUMENT_DATE ,23)
        							}    
        							
        							
        							disstr.push(rawName+' '+conName+' '+"("+orderDir+")");
    				}else{  //如果不是in
    					
        						if(panelItems[1].getValue() == '='){
        							orderDir = '';
        							orderDir = panelItems[3].getRawValue();  //获取第一个textfield值  [2]为date，[3]为text 
        					
        					
        							if(panelItems[0].getValue() == 'update_time'){
        								str.push('convert(varchar,UPDATE_TIME ,23)'+' '+'like'+' '+"'"+orderDir+"%'");
        							}
        							if(panelItems[0].getValue() == 'document_date'){
        							str.push('convert(varchar,DOCUMENT_DATE ,23)'+' '+'like'+' '+"'"+orderDir+"%'");
        							}
        							if(panelItems[0].getValue() == 'INVOICE_DATE'){
        								str.push('convert(varchar,INVOICE_DATE ,23)'+' '+'like'+' '+"'"+orderDir+"%'");
        							}
        							if(panelItems[0].getValue() == 'EXPRESS_DATE'){
        							str.push('convert(varchar,EXPRESS_DATE ,23)'+' '+'like'+' '+"'"+orderDir+"%'");
        							}
        							
        						}else if(panelItems[1].getValue() != 'like'){
        						
        							orderDir = '';
        							orderDir = panelItems[3].getRawValue();  //获取第一个textfield值  [2]为date，[3]为text 
        					
        					
        							if(panelItems[0].getValue() == 'update_time'){
        								str.push('convert(varchar,UPDATE_TIME ,23)'+' '+conName+' '+"'"+orderDir+"'");
        							}
        							if(panelItems[0].getValue() == 'document_date'){
        							str.push('convert(varchar,DOCUMENT_DATE ,23)'+' '+conName+' '+"'"+orderDir+"'");
        							}
        							if(panelItems[0].getValue() == 'INVOICE_DATE'){
        								str.push('convert(varchar,INVOICE_DATE ,23)'+' '+conName+' '+"'"+orderDir+"'");
        							}
        							if(panelItems[0].getValue() == 'EXPRESS_DATE'){
        							str.push('convert(varchar,EXPRESS_DATE ,23)'+' '+conName+' '+"'"+orderDir+"'");
        							}	
        						}
    					disstr.push(rawName+' '+conName+' '+"'"+orderDir+"'");  //显示值
    				}
    			}else{//不使用日期
    				orderDir = panelItems[2].getValue();  //2为text，3为date
    				PrintDetailArray[i][2] = orderDir;
    				PrintDetailArray[i][4] = 2;
    				if(panelItems[1].getValue() == 'in'){
//    					SearchDetailArray[i][1] = 'in';
    					orderDir = '';
    					orderTemp = panelItems[2].getValue();
//    					SearchDetailArray[i][2] = orderTemp;
        				for(var k=0;k<orderTemp.split(",").length;k++){
        					orderDir += "'"+orderTemp.split(",")[k]+"'";
        					if(k+1 != orderTemp.split(",").length){orderDir += ',';} 
        				}
    					str.push(fieldName+' '+conName+' '+"("+orderDir+")");
    					disstr.push(rawName+' '+conName+' '+"("+orderDir+")");
    				}else{
    					if(panelItems[1].getValue() == 'like'){
    						str.push(fieldName+' '+conName+' '+"'%"+orderDir+"%'");
//    						SearchDetailArray[i][1] = conName;
    					}else{
    						str.push(fieldName+' '+conName+' '+"'"+orderDir+"'");
//    						SearchDetailArray[i][1] = conName;
    					}
    					disstr.push(rawName+' '+conName+' '+"'"+orderDir+"'");
    				}
    			}
    		}
//    		i+1 != paramPanels.length ? str.push(fieldName+'='+orderDir+',') : str.push(fieldName+'='+orderDir);//拼写orderby语句，若为最后用一个，无","连接
    		for(var b=0;b<PrintDetailArray[i].length;b++){
    			if(PrintDetailArray[i][b] ==null || PrintDetailArray[i][b] == ''){
    				PrintDetailArray[i][b] = '';
    			}
    		}
    	} 
    	var hash = {};        
    	for(var i in fieldNames) {//判断字段名有无重复     
            if(hash[fieldNames[i]]){ 
            	 Share.ShowMessage("I0052");
                 return ;      
            }
            hash[fieldNames[i]] = true;           
        }  
    	for(var c=0;c<PrintDetailArray.length;c++){
    		for(var x=0;x<PrintDetailArray[c].length;x++){
//    			console.log(SearchDetailArray[c][x]);
    		}
    	}
    	store.currentPage = 1;
    	store.removeAll();
          store.on('beforeload', function(store) {
     			Ext.apply(store.proxy.extraParams , {
     								  str:str.join(" and ")
	                                 ,state1:state1
	                                 ,state2:state2
	                                 ,type:type
	                                 ,startnum:null
	          				   		 ,endnum:null
	                                 ,nums:null
	                                 ,startday:null
	                                 ,endday:null
	                                 ,doc_no:null
	                                 ,doc_no_2:null
	                                 ,custname:null
	                                 ,goodsname:null
	                                 ,order_paramm:null
     				});
          });
 		store.load();
 		var win = button.up('window');
    	win.hide();
    	OldPrint = win;
    }
  },

    save : function(win) {
    	
    },
    
    init: function(application) {
        this.control({
            "button": {
                click: this.onButtonClick
            }
        });
    }
});
